package com.ca.demo.config.security;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;

/**
 * @Author XieLei
 * @Date 2017/6/22 10:39
 */
public class SecurityUser implements UserDetails {

    private Long userId;
    private String username;
    private String password;
    private Boolean enabled;
    private Boolean locked;

    public SecurityUser(Long userId, String username, String password, Boolean enabled, Boolean locked) {
        this.userId = userId;
        this.username = username;
        this.password = password;
        this.enabled = enabled;
        this.locked = locked;
    }

    public SecurityUser(Long userId, String username, String password) {
        this(userId, username, password, true, false);
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.EMPTY_LIST;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return !locked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }
}
